package engine.logic.login
{
	public class NxCallLater
	{
		public function NxCallLater()
		{
		}
		
		private var _showQueue:Array=[];
		
		private var _readyCondition:uint=0x00;
		
		/**
		 * 延迟调用 
		 * @param condition
		 * @param oper
		 * @param param
		 * 
		 */		
		public function callLater(condition:uint,oper:Function,param:Object=null):void
		{
			var obj:Object={condition:condition,oper:oper,param:param};
			
			_showQueue.push(obj);
			
			callShowOper();
		}
		
		/**
		 * 条件准备好 
		 * @param condition
		 * 
		 */		
		public function setReady(condition:uint):void
		{
			_readyCondition=	_readyCondition|condition;
			
			callShowOper();
		}
		
		/**
		 * 条件置空 
		 * @param condition
		 * 
		 */		
		public function setZero(condition:uint):void
		{
			_readyCondition	=_readyCondition & condition;
		}
		
		private function callShowOper():void
		{
			var condition:uint;
			var oper:Function;
			var param:Object;
			var len:uint	=	_showQueue.length;
			
			for(	var i:uint	=0	;	i<len;	i++	)
			{
				condition=_showQueue[i].condition;
				oper=_showQueue[i].oper;
				param=_showQueue[i].param;
				
				if((	_readyCondition	&condition	)	==	condition)
				{
					oper.apply(null,param);
					_showQueue.splice(i,1);
					
					i	--;
					len	--;
				}
			}
		}
	}
}